package Controller.Customer;

import Dao.CustomerCompanyDao;
import Service.CustomerService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "ListCustomer", value = "/ListCustomer")
public class ListCustomer extends HttpServlet {
    private CustomerService customerService = new CustomerService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        CustomerCompanyDao firmDao = new CustomerCompanyDao();
        String nickname = request.getParameter("nickname");
        String pageNum = request.getParameter("pageNum");
        try {
            List<String> customerList = firmDao.selectFirm(); // Assuming this method exists and is correctly implemented
            Map<String, Object> map = customerService.selectCustomerByPage(pageNum == null ? 1 : Integer.valueOf(pageNum), nickname);
            request.setAttribute("customerList", customerList);
            request.setAttribute("map", map);
            request.getRequestDispatcher("/ListCustomer.jsp").forward(request, response);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}